const{ethers} =require("hardhat");
const {expect} = require("chai");

describe("NftAuction Contract", function () {
    let contract;

    beforeEach(async function () { 
        [owner, account1, account2,] = await ethers.getSigners();
        const fatory = await ethers.getContractFactory("NftAuction");
        contract = await fatory.deploy();

        // fatory.waitForDeployment();
        expect(await contract.getAddress()).to.properAddress;
    });

    it("create auction",async()=>{
        const tx = await contract.createAuction(1000000, 60,ethers.ZeroAddress, 0);
        const receipt = await tx.wait();

        const filter = contract.filters.CreateAuction(null, null, null, null, null,null);
        const events = await contract.queryFilter(filter, receipt.blockNumber, receipt.blockNumber);
       const auctionId = events[0].args.auctionId;
        expect(auctionId).to.equal(0);

        await contract.connect(account1).bid(0,{value:ethers.parseEther("0.0001")})

        const auction= await contract.getAuction(0);
        expect(auction.highestBidder).to.equal(account1);
    })
});